import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { ShopMallEventName } from "../ShopMallEventName";
import { SShopItem } from "../../../../../Message/Public/SShopItem";
import { ItemData } from "../../../resource/info/ItemData";
import { ColorConfig } from "../../../resource/ColorConfig";
import { ECategory } from "../../../../../Message/Public/ECategory";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { Language } from "../../../../../extend/language/Language";
import { EPrictUnit } from "../../../../../Message/Public/EPrictUnit";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { BaseItem } from "../../common/BaseItem";
import { GLabel } from "../../../../../com/mui/controls/GLabel";
import { GNumericStepper } from "../../../../../com/mui/controls/GNumericStepper";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { MsgManager } from "../../../manager/MsgManager";
import { BuyAlert } from "../../pet/BuyAlert";
import { PulseSharedObject } from "../../player/PulseSharedObject";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { CheckBoxWin } from "../../common/alertwins/CheckBoxWin";
import { TItem } from "../../../../../Message/Db/Tables/TItem";
import { ColorInfo } from "../../../resource/info/ColorInfo";
type int = number;
//class GoodRender
    
    export  class GoodRender extends GCellRenderer
    {
        constructor()
        {
            super();
            this._oIngot = new Object /* flash.display.Bitmap */();
            this._pIngot = new Object /* flash.display.Bitmap */();
            this.createChildren();
            Dispatcher.addEventListener(ShopMallEventName.NPCShopMallWindowClose, this.onNPCShopMallWindowCloseHandler);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            this.shopItem = arg1 as SShopItem;
            if (this.shopItem) 
            {
                this.itemData = new ItemData(this.shopItem.itemCode);
                this._priceType = this.shopItem.reserve1;
                this.item = this.itemData.itemInfo.item;
                this.colorInfo = ColorConfig.instance.getItemColor(this.item.color);
                if (this.colorInfo) 
                {
                    this.colorName = this.colorInfo.color;
                }
                if (this.itemData.category != ECategory._ECategoryMount) 
                {
                    this._propItem.toolTipType = ItemData.ToolTipType_Pack;
                }
                else 
                {
                    this._propItem.toolTipType = ItemData.ToolTipType_Mounts;
                }
                this._propItem.itemData = this.itemData;
                this._propItem.drawNow();
                this._propItem.amount = -1;
                this._propItem.setSize(60, 60);
                this._nameLabel.htmlText = HTMLUtil.addColor(this.item.name, this.colorName);
                this._priceImgName = GameDefConfig.instance.getEPrictUnitImg(this._priceType);
                if (this._priceImgName != "") 
                {
                    this._oIngot.bitmapData = GlobalClass.getBitmapData(this._priceImgName);
                    this._pIngot.bitmapData = GlobalClass.getBitmapData(this._priceImgName);
                }
                this._oPriceNumLabel.htmlText = HTMLUtil.addColor(this.shopItem.price.toString(), "#F4FF01");
                this._oPriceNumLabel.drawNow();
                this._oPriceNumLabel.x = this._oIngot.x - this._oPriceNumLabel.width;
                this._redLine.graphics.lineStyle(2, 16711680, 0.75);
                this._redLine.graphics.moveTo(151, 21);
                this._redLine.graphics.lineTo(167, 32);
                this._pPriceNumLabel.htmlText = HTMLUtil.addColor(this.shopItem.discount.toString(), "#F4FF01");
                this._pPriceNumLabel.drawNow();
                this._pPriceNumLabel.x = this._pIngot.x - this._pPriceNumLabel.width;
                this._amountText.text = Language.getStringByParam(53027, this.shopItem.amout);
                if (this._priceType == EPrictUnit._EPriceUnitCoinBind || this._priceType == EPrictUnit._EPriceUnitCoin) 
                {
                    this._oPriceLabel.visible = false;
                    this._oPriceNumLabel.visible = false;
                    this._oIngot.visible = false;
                    this._redLine.visible = false;
                    this._pIngot.y = 34;
                    this._pPriceLabel.htmlText = HTMLUtil.addColor(Language.getString(53020), "#f0ea3f");
                }
                else 
                {
                    this._oPriceLabel.visible = true;
                    this._oPriceNumLabel.visible = true;
                    this._oIngot.visible = true;
                    this._redLine.visible = true;
                    this._pIngot.y = 37;
                    this._pPriceLabel.htmlText = HTMLUtil.addColor(Language.getString(53014), "#00FF1F");
                }
            }
            return;
        }

        /* internal  */createChildren(): void
        {
            this._windowCenterB = ResouceConst.getScaleBitmap("WindowCenterB");
            this._windowCenterB.width = 200;
            this._windowCenterB.height = 100;
            this.addChild(this._windowCenterB);
            this._bg = GlobalClass.getBitmap("PropBg");
            this._bg.x = 5;
            this._bg.y = 17;
            this.addChild(this._bg);
            this._propItem = new BaseItem();
            this._propItem.isDragAble = false;
            this._propItem.label = "";
            this._propItem.move(10, 22);
            this.addChild(this._propItem);
            this._nameLabel = new GLabel();
            this._nameLabel.x = 80;
            this._nameLabel.y = 2;
            this.addChild(this._nameLabel);
            this._oPriceLabel = new GLabel();
            this._oPriceLabel.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._oPriceLabel.htmlText = HTMLUtil.addColor(Language.getString(53013), "#B0EFFF");
            this._oPriceLabel.x = 80;
            this._oPriceLabel.y = 18;
            this.addChild(this._oPriceLabel);
            this._oPriceNumLabel = new GLabel();
            this._oPriceNumLabel.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._oPriceNumLabel.x = 150;
            this._oPriceNumLabel.y = 18;
            this.addChild(this._oPriceNumLabel);
            this._oIngot = new Object /* flash.display.Bitmap */();
            this._oIngot.x = 170;
            this._oIngot.y = 20;
            this.addChild(this._oIngot);
            this._pIngot = new Object /* flash.display.Bitmap */();
            this._pIngot.x = 170;
            this._pIngot.y = 37;
            this.addChild(this._pIngot);
            this._redLine = new Object /* flash.display.Shape */();
            this.addChild(this._redLine);
            this._pPriceLabel = new GLabel();
            this._pPriceLabel.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._pPriceLabel.htmlText = HTMLUtil.addColor(Language.getString(53014), "#00FF1F");
            this._pPriceLabel.x = 80;
            this._pPriceLabel.y = 35;
            this.addChild(this._pPriceLabel);
            this._pPriceNumLabel = new GLabel();
            this._pPriceNumLabel.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._pPriceNumLabel.x = 150;
            this._pPriceNumLabel.y = 35;
            this.addChild(this._pPriceNumLabel);
            this._amountText = new Object /* flash.text.TextField */();
            this._amountText.textColor = 15788607;
            this._amountText.x = 80;
            this._amountText.y = 52;
            this.addChild(this._amountText);
            this._numericStepper = new GNumericStepper();
            this._numericStepper.setSize(60, 22);
            this._numericStepper.move(80, 70);
            this._numericStepper.styleName = "NumericStepper";
            this._numericStepper.addEventListener(flash.events.Event.CHANGE, this.onBuyNumChange);
            this._numericStepper.drawNow();
            this._numericStepper.textField.setStyle("upSkin", GlobalClass.getScaleBitmap("WindowCenterB", new Object /* flash.geom.Rectangle */(4, 4, 36, 21)));
            this._numericStepper.textField.drawNow();
            this._numericStepper.maximum = 99;
            this._numericStepper.minimum = 1;
            this.addChild(this._numericStepper);
            this._buyBtn = new GButton();
            this._buyBtn.label = Language.getString(53016);
            this._buyBtn.styleName = "Button";
            this._buyBtn.setSize(48, 25);
            this._buyBtn.move(145, 70);
            this._buyBtn.drawNow();
            this._buyBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBuyBtnClickhandler);
            this.addChild(this._buyBtn);
            return;
        }

        /* internal  */onBuyNumChange(arg1: Object /* flash.events.Event */): void
        {
            if (this._numericStepper.value > this.shopItem.amout) 
            {
                this._numericStepper.value = this.shopItem.amout;
            }
            return;
        }

        /* internal  */onBuyBtnClickhandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var event: Object /* flash.events.MouseEvent */;
            var amount: int;
            var totalPrice: number;
            var unitName: string;
            var isAbundant: Boolean;
            var amountStr: string;
            var htmlContent: string;
            var isNeedAlert: Boolean;
            var onClickHandler: Function;

            var loc1;
            amount = 0;
            event = arg1;
            if (this.shopItem.amout == 0) 
            {
                MsgManager.showRollTipsMsg(Language.getString(53028));
                return;
            }
            this.onBuyNumChange(null);
            amount = this._numericStepper.value;
            totalPrice = this.shopItem.discount * amount;
            unitName = GameDefConfig.instance.getEPrictUnitName(this._priceType);
            isAbundant = BuyAlert.checkMoney(this._priceType, totalPrice);
            if (isAbundant == false) 
            {
                return;
            }
            amountStr = HTMLUtil.addColor(amount.toString(), "#FF0000");
            htmlContent = Language.getStringByParam(53030, amountStr, this._nameLabel.htmlText, totalPrice, unitName);
            isNeedAlert = !PulseSharedObject.isTodayNotTips("NPCBuyAlert");
            if (isNeedAlert) 
            {
                onClickHandler = (arg1: int, arg2: Boolean): void
                {
                    if (arg1 == Alert.OK) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.ShopBuyNpcItem, {"itemCode": shopItem.itemCode, "itemCount": amount}));
                        Alert.resetToDefault();
                    }
                    if (arg2) 
                    {
                        PulseSharedObject.save("NPCBuyAlert", true);
                    }
                    return;
                }
                Alert.alertWinRenderer = CheckBoxWin;
                Alert.show(htmlContent, null, Alert.OK | Alert.CANCEL, null, onClickHandler);
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopBuyNpcItem, {"itemCode": this.shopItem.itemCode, "itemCount": amount}));
            }
            return;
        }

        /* internal  */onNPCShopMallWindowCloseHandler(arg1: DataEvent): void
        {
            this._numericStepper.value = 1;
            return;
        }

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameLabel: GLabel;

        /* internal */ /* var */_propItem: BaseItem;

        /* internal */ /* var */_oPriceLabel: GLabel;

        /* internal */ /* var */_pPriceLabel: GLabel;

        /* internal */ /* var */_oPriceNumLabel: GLabel;

        /* internal */ /* var */_pPriceNumLabel: GLabel;

        /* internal */ /* var */_oIngot: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_pIngot: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_buyBtn: GButton;

        /* internal */ /* var */_windowCenterB: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_numericStepper: GNumericStepper;

        /* internal */ /* var */_redLine: Object /* flash.display.Shape */;

        /* internal */ /* var */_amountText: Object /* flash.text.TextField */;

        /* internal */ /* var */_priceType: int;

        /* internal */ /* var */_priceImgName: string;

        /* internal */ /* var */shopItem: SShopItem;

        /* internal */ /* var */item: TItem;

        /* internal */ /* var */itemData: ItemData;

        /* internal */ /* var */colorInfo: ColorInfo;

        /* internal */ /* var */colorName: string;
    }
